package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.consts.ErmsCodePrefix;
import com.sugon.dao.SpecialDevHoistingEquDao;
import com.sugon.entity.SpecialDevHoistingEquEntity;
import com.sugon.service.SpecialDevHoistingEquService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 特种设备-起重设备台账Service实现类
 *
 * @author sugon
 * @date 2021-09-08 16:30:39
 */
@Service("specialDevHoistingEquService")
public class SpecialDevHoistingEquServiceImpl implements SpecialDevHoistingEquService {

    @Autowired
    private SpecialDevHoistingEquDao specialDevHoistingEquDao;

    @Override
    public SpecialDevHoistingEquEntity queryObject(String id) {
        return specialDevHoistingEquDao.queryObject(id);
    }

    @Override
    public List<SpecialDevHoistingEquEntity> queryList(Map<String, Object> map) {
        return specialDevHoistingEquDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return specialDevHoistingEquDao.queryTotal(map);
    }

    @Override
    public String generateUniqueCode() {
        String lastestEquipmentCode = specialDevHoistingEquDao.getLastestEquipmentCode(ErmsCodePrefix.HOISTING_EQU_CODE_PREFIX);
        return com.sugon.modules.utils.StrUtil.increase(lastestEquipmentCode, ErmsCodePrefix.HOISTING_EQU_CODE_PREFIX, 5, 1);
    }

    @Override
    public int save(SpecialDevHoistingEquEntity specialDevHoistingEqu) {
        specialDevHoistingEqu.setId(RandomUtil.randomString(32));
        specialDevHoistingEqu.setGmtCreate(DateUtil.date());
        specialDevHoistingEqu.setCreateUser(ShiroUtils.getUserId());
        specialDevHoistingEqu.setEquipmentCode(generateUniqueCode());
        return specialDevHoistingEquDao.save(specialDevHoistingEqu);
    }

    @Override
    public int update(SpecialDevHoistingEquEntity specialDevHoistingEqu) {
        specialDevHoistingEqu.setGmtModified(DateUtil.date());
        specialDevHoistingEqu.setUpdateUser(ShiroUtils.getUserId());
        return specialDevHoistingEquDao.update(specialDevHoistingEqu);
    }

    @Override
    public int delete(String id) {
        return specialDevHoistingEquDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return specialDevHoistingEquDao.deleteBatch(ids);
    }
}
